﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SBLib.RSS;

using SBLib.Common;
using System.Data.SqlClient;
using System.Data;
using SBLib.Common.EmailKS;
using System.ComponentModel;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using SBLib.Common.DbKS;
using SBLib.Common.SqlServerKS;
using SBLib.Common.CsvKS;

namespace TestApp
{
    class Program
    {
        public delegate void Calculate(int one, int two);

        private static void MailDeliveryComplete(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                ((SmtpClient)sender).Dispose();
                if (e.Cancelled)
                {
                    Console.WriteLine("[{0}] Send canceled.", e.UserState);
                }
                if (e.Error != null)
                {
                    Console.WriteLine("Error : {0}", e.Error.ToString());
                }
                else
                {
                    Console.WriteLine("success : {0}", e.UserState);
                }
            }
            catch (Exception)
            {
                
            }

        }

        static void Main(string[] args)
        {

           // C:\Users\Administrator\Desktop\testcsv.csv
            var ret1 = CsvReadFuncKS.CsvLineCount (@"C:\Users\Administrator\Documents\testcsv.csv");
            Console.WriteLine(ret1.ToString());

            var ret = CsvReadFuncKS.CsvToDataTable(@"", false);
            var fdf = "";
            //SqlServerFuncKS ddd = new SqlServerFuncKS("Data Source=192.168.203.220;Initial Catalog=IkeaMainDBEvent;User ID=sa;Password=masterkey");
            //var re = ddd.GetDatabaseTables("IkeaMainDBEvent");

            //var dd = "";

            //Console.ReadLine();

            //for (int i = 0; i < 5; i++)
            //{
            //    KSEmail em = new KSEmail("mail.lavender.ad", 25, "digidev", "viewsonic");
            //    em.FromEmail("fldkfld@lavender.ad", "TestName");
            //    em.ToEmail("sumon.b@lavender.ad", "Sumon");
            //    em.MailBody("I am a test mail", false);
            //    em.SendEmail();

            //}

          //  Stopwatch stopWatch = new Stopwatch();
          //  stopWatch.Start();

          //  //for (int i = 0; i < 100; i++)
          //Parallel.For(0, 2, delegate(int i)
          //  {

          //      EmailFuncKS em = new EmailFuncKS("mail.lavender.ad", 25, "digidev", "viewsonic");
          //      em.FromEmail("fldkfld@lavender.ad", "TestName");
          //      em.ToEmail("sumon.b@lavender.ad", "Sumon");
          //      em.MailBody("I am a test mail", false);
          //      em.SendEmailAsync(MailDeliveryComplete);
          //      Console.WriteLine("Sending...");
          //  }
          //  );

          //stopWatch.Stop();
          //TimeSpan ts = stopWatch.Elapsed;

          //// Format and display the TimeSpan value.
          //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
          //    ts.Hours, ts.Minutes, ts.Seconds,
          //    ts.Milliseconds / 10);
          //Console.WriteLine(elapsedTime, "RunTime");

            
           
            //for (int i = 0; i < 10; i++)
            //{

            //    KSEmail em = new KSEmail("mail.lavender.ad", 25, "digidev", "viewsonic");
            //    em.FromEmail("fldkfld@lavender.ad", "TestName");
            //    em.ToEmail("sumon.b@lavender.ad", "Sumon");
            //    em.MailBody("I am a test mail", false);
            //    em.SendEmailAsync(MailDeliveryComplete);
            //}




            Console.ReadLine();
                        

               //var connectionString = @"Data Source=192.168.203.220;Initial Catalog=ikeamaindb;User ID=sa;Password=masterkey";

               // SqlDataAdapter dataAdapter = new SqlDataAdapter("select *from testTable", connectionString);
               // SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

               // // Populate a new data table and bind it to the BindingSource.
               // DataTable table = new DataTable();
               // table.Locale = System.Globalization.CultureInfo.InvariantCulture;
               // dataAdapter.Fill(table);

                //DataTableWriter dw = new DataTableWriter(@"c:\sumontest.csv", table,@",");
                //dw.WriteToFile();
                
       
               //SQLWriter sw = new SQLWriter(@"c:\sumontest.csv", @",", connectionString, @"select *from customer");
               //sw.WriteToFile();

               //List<Customer> cust = new List<Customer>()
               //{
               //  new Customer(1,"a",32),
               //  new Customer(1,"sumon,b",32),
               //  new Customer(2,"razu",30)
               //};


               //CustomObjectWriter cs = new CustomObjectWriter(@"c:\sumontest.csv", @",");
               //cs.WriteToFile<Customer>(cust);

               //RssReader rr = new RssReader();
               //SBLib.RSS.Model.ModelRssInfo mod = rr.ReadRssFeed("http://forums.ten.com.au/forums/rss/rssannounce.jspa?categoryID=70");


               //[{"Age":32,"CustomerName":"a","ID":1},{"Age":32,"CustomerName":"sumon,b","ID":1},{"Age":30,"CustomerName":"razu","ID":2}]

               ////string a = JsonHelper.SerializeCollection<Customer>(cust);
               //string a = JsonHelper.SerializeCollection<Customer>(cust);
               ////string a = JsonHelper.SerializeSingle<Customer>(cust[0]);


               //////var r = JsonHelper.DeserializeSingle<Customer>(a);
               ////var r = JsonHelper.DeserializeCollection<Customer>(a);

               //string ss = XmlFunc.TransformDatabaseDataToXml(connectionString, "select *from customer", "customers","customer");


               
               //p.GetDataTable("1007151722395");

               
               

           
        }

        public static void Sum(int one, int two)
        {
            Console.WriteLine((one + two).ToString());
        }


        public static void Mul(int one, int two)
        {
            Console.WriteLine((one * two).ToString());
        }

    }
}
